// my_dian/dui/dui.js
let app = getApp()
let yuming = app.globalData.yuming;
var shuzong = []
var shu = []
const util = require('../../config/util.js')
const request = require('../../config/request');
Page({

  /**
   * 页面的初始数据
   */
  ...request,
  data: {
    yuming: yuming,
    title: '签到',
    page: 1,
    gongwu: false,
    dateString: "",
    spot: ['2022/2/18', '2022/2/17', '2022/2/16', '2022/2/15'],
    paiming: [{}, {}, {}, {}, {}, {}, {}, {}, {}],
    lie: [],
    lian: [{
      name: '我的积分',
      url: '/my_other/myjifen/myjifen'
    }, {
      name: '兑换记录',
      url: '/my_other/duihuanjl/duihuanjl'
    }],
    lian_index: 2,
    cishu: '',
    gdgg:[],
  },
  // 查看更多
  lookmore() {
    shuzong = this.data.lie
    this.setData({
      page: (this.data.page) + 1
    })
    this.getspList();
  },
  getspList() {
    wx.showLoading({
      title: '加载中',
      icon: 'none'
    })
    let that = this;
    this.myRequest(yuming + 'shop/scan_pay_goodslist', {
      shopId: wx.getStorageSync('shopId'),
      page: that.data.page, 
    }, "POST").then(res => {
      if (res.data.code == 200) {
        wx.hideLoading();
        shu = res.data.data
        if (that.data.page != 1) {
          if (shu.length != 10) {
            that.setData({
              gongwu: true
            })
          }
        }
        this.setData({
          lie: shuzong.concat(shu), //商品列表
        })
      }
    })
  },
  getCishu() {
    this.myRequest(yuming + 'shop/scan_shop_total', {
      shopId: wx.getStorageSync('shopId'),
    }, "POST").then(res => {
      if (res.data.code == 200) {
        let gdgg = [];
        res.data.data.list_yd.forEach(item => {
          if (item.Goods != null && item.Shop != null) {
            gdgg.push(`${item.Shop.shopName}  已兑换${item.Goods.title}`)
          }
        })
        this.setData({
          cishu: res.data.data,
          gdgg
        })
      }
    })
  },
  zfms() {
    wx.navigateTo({
      url: '/page_other/saomnum/saomnum',
    })
  },
  dhjl() {
    wx.navigateTo({
      url: '/my_other/duihuanjl/duihuanjl',
    })
  },
  // // 我的积分 兑换记录
  // bindlian(e) {
  //   var index = e.currentTarget.dataset.index;
  //   var url = e.currentTarget.dataset.url;
  //   this.setData({
  //     lian_index: index
  //   })
  //   wx.navigateTo({
  //     url: url,
  //   })
  //   var that = this
  //   setTimeout(function () {
  //     that.setData({
  //       lian_index: 3
  //     })
  //   }, 1000)
  // },
  // 去兑换
  qudui(e) {
    let id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/my_other/dingdan/dingdan?id=' + id,
    })
  },
  // 商品详情
  spxq(e) {
    let id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/my_dian/spxq/spxq?id=' + id,
    })
  },
  // 兑换商品
  qiandao() {
    wx.navigateTo({
      url: '/my_dian/duishang/duishang',
    })
  },
  dateChange(e) {
    console.log("选中日期变了,现在日期是", e.detail.dateString)
    this.setData({
      dateString: e.detail.dateString
    })
  },
  backs() {
    // wx.reLaunch({
      // url: '/pages/index/index',
    // })
    wx.navigateBack({
      delta: 1
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      heights: wx.getMenuButtonBoundingClientRect().top + 5
    })
    var today = new Date();
    var h = today.getFullYear();
    var m = today.getMonth() + 1;
    m = m < 10 ? "0" + m : m;
    this.setData({
      dateguo: h + "-" + m
    })
    this.getspList();
  },
  onShow: function () {
    this.getCishu();
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },
})